use std::{env, fs};

fn main() {
	println!("cargo:rerun-if-changed=build.rs");
	println!("cargo:rustc-link-search=native=./deps/libs");
	println!("cargo:rustc-link-lib=dylib=zint");


	// 获取目标架构
    let dll_dir = "deps/libs";

    // 获取输出目录（如 target/debug 或 target/release）
    let out_dir = env::var("OUT_DIR").unwrap();
    let target_dir = std::path::Path::new(&out_dir)
        .ancestors()  // 向上回溯到 target 目录
        .nth(3)
        .unwrap();

    // 拷贝 DLL 到目标目录
    for entry in std::fs::read_dir(dll_dir).unwrap() {
        let entry = entry.unwrap();
        let dll_path = entry.path();
        let dest_path = target_dir.join(dll_path.file_name().unwrap());
        fs::copy(&dll_path, &dest_path).unwrap();
    }
}
